﻿namespace WMS6.Web.OrderManagement
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.OrderMgtServiceRef;

    public class PurchaseOrder : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnAddDetail;
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnGoBack;
        protected Button btnImportData;
        protected Button btnInputPO;
        protected Button btnNew;
        protected Button btnSave;
        protected DropDownList ddlApportionRule;
        protected DropDownList ddlIncoTerms;
        protected DropDownList ddlPaymentTerm;
        protected DropDownList ddlPoType;
        protected DropDownList ddlStatus;
        protected DropDownList ddlTransMode;
        protected HtmlForm F3011;
        protected GridView gvPurchaseOrderDetail;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnCopy;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnPageQty;
        protected HtmlInputHidden hdnPageType;
        protected HtmlInputHidden hdnpoID;
        protected HiddenField hdnServerPoID;
        protected HtmlInputButton htmlbtnReport;
        protected HtmlImage imgOwnerID;
        protected Label lblApportionRule;
        protected Label lblCarrier;
        protected Label lblClosedDate;
        protected Label lblCreatedBy;
        protected Label lblCreatedDate;
        protected Label lblDesCountry;
        protected Label lblExternalPoID;
        protected Label lblExternalPoID2;
        protected Label lblIncoTerms;
        protected Label lblMsg;
        protected Label lblOtherRef;
        protected Label lblOwner;
        protected Label lblOwner_Address;
        protected Label lblOwner_City;
        protected Label lblOwner_Contact;
        protected Label lblOwner_Country;
        protected Label lblOwner_Email;
        protected Label lblOwner_Fax;
        protected Label lblOwner_Phone;
        protected Label lblOwner_Prov;
        protected Label lblOwner_Ref;
        protected Label lblOwner_Vat;
        protected Label lblOwner_Zip;
        protected Label lblOwnerID;
        protected Label lblOwnerName;
        protected Label lblPaymentTerm;
        protected Label lblPlaceOfDelivery;
        protected Label lblPlaceOfDischarge;
        protected Label lblPlaceOfLoading;
        protected Label lblPoDate;
        protected Label lblPoGroup;
        protected Label lblPoID;
        protected Label lblPoType;
        protected Label lblRemark;
        protected Label lblRequestDeliveryDate;
        protected Label lblSealNo;
        protected Label lblSrcCountry;
        protected Label lblStatus;
        protected Label lblTransMode;
        protected Label lblUdf04;
        protected Label lblUdf09;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblVendor_Address;
        protected Label lblVendor_City;
        protected Label lblVendor_Contact;
        protected Label lblVendor_Country;
        protected Label lblVendor_Email;
        protected Label lblVendor_Fax;
        protected Label lblVendor_Phone;
        protected Label lblVendor_Prov;
        protected Label lblVendor_Ref;
        protected Label lblVendor_Vat;
        protected Label lblVendor_Zip;
        protected Label lblVendorID;
        protected Label lblVendorName;
        protected Label lblVessel;
        protected Label lblVesselDate;
        protected Label lblVoyge;
        protected LinkButton lnkbtnClose;
        protected LinkButton lnkbtnPrintPO;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected Label one6;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnClose;
        protected HtmlTableCell tdlnkbtnPrintPO;
        protected TextBox txtCarrier;
        protected TextBox txtClosedDate;
        protected TextBox txtCreatedBy;
        protected TextBox txtCreatedDate;
        protected TextBox txtDesCountry;
        protected TextBox txtExternalPoID;
        protected TextBox txtExternalPoID2;
        protected TextBox txtOtherRef;
        protected TextBox txtOwner_Address;
        protected TextBox txtOwner_City;
        protected TextBox txtOwner_Contact;
        protected TextBox txtOwner_Country;
        protected TextBox txtOwner_Email;
        protected TextBox txtOwner_Fax;
        protected TextBox txtOwner_Phone;
        protected TextBox txtOwner_Porv;
        protected TextBox txtOwner_Ref;
        protected TextBox txtOwner_Vat;
        protected TextBox txtOwner_Zip;
        protected TextBox txtOwnerID;
        protected TextBox txtOwnerName;
        protected TextBox txtPlaceOfDelivery;
        protected TextBox txtPlaceOfDischarge;
        protected TextBox txtPlaceOfLoading;
        protected TextBox txtPoDate;
        protected TextBox txtPoGroup;
        protected TextBox txtPoID;
        protected TextBox txtRemark;
        protected TextBox txtRequestDeliveryDate;
        protected TextBox txtSealNo;
        protected TextBox txtSrcCountry;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected TextBox txtVendor_Address;
        protected TextBox txtVendor_City;
        protected TextBox txtVendor_Contact;
        protected TextBox txtVendor_Country;
        protected TextBox txtVendor_Email;
        protected TextBox txtVendor_Fax;
        protected TextBox txtVendor_Phone;
        protected TextBox txtVendor_Porv;
        protected TextBox txtVendor_Ref;
        protected TextBox txtVendor_Vat;
        protected TextBox txtVendor_Zip;
        protected TextBox txtVendorID;
        protected TextBox txtVendorName;
        protected TextBox txtVessel;
        protected TextBox txtVesselDate;
        protected TextBox txtVoyge;

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                {
                    if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F3100_007");
                    }
                    else
                    {
                        if (this.hdnFlag.Value == "0")
                        {
                            this.InsertPurchaseOrderInfo();
                        }
                        base.Response.Redirect(string.Format("PurchaseOrderDetail.aspx?from={0}&ID={1}&SeqNO={2}&OwnerID={3}&VendorID={4}", new object[] { base.UrlEncode(this.hdnFrom.Value), base.UrlEncode(this.txtPoID.Text.Trim()), base.UrlEncode(this.hdnLineID.Value), base.UrlEncode(this.txtOwnerID.Text.Trim()), base.UrlEncode(this.txtVendorID.Text.Trim()) }), false);
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F3100_008");
                }
            }
            catch (Exception ex)
            {
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtPoID.Text = "";
            this.txtPoID.Enabled = true;
            this.ddlStatus.SelectedValue = "New";
            this.hdnpoID.Value = "";
            this.txtClosedDate.Text = "";
            this.hdnFlag.Value = "0";
            this.hdnPageQty.Value = "0";
            this.hdnCopy.Value = "1";
            this.btnSave.Enabled = true;
            this.btnAddDetail.Visible = false;
            this.btnDeleteDetail.Visible = false;
            this.btnImportData.Visible = false;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtPoID.Text.Trim()))
            {
                try
                {
                    if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F3100_006");
                    }
                    else
                    {
                        List<string> poIDs = new List<string> {
                            this.txtPoID.Text.Trim()
                        };
                        this.lblMsg.Text = OrderMgtServiceClientProxy.GetInstance().DeletePurchaseOrderInfo(poIDs) + base.GetGlobalMsgResource("C006");
                        this.btnSave.Enabled = false;
                        this.btnDelete.Enabled = false;
                        this.btnCopy.Enabled = false;
                        base.DataEntityViewState = null;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtPoID.Text.Trim()) && (this.hdnFlag.Value == "1"))
            {
                List<string> poIDS = base.GetSelectedIDsInGridView(this.gvPurchaseOrderDetail, "poID");
                List<string> lineID = base.GetSelectedIDsInGridView(this.gvPurchaseOrderDetail, "lineID");
                List<string> listStatus = base.GetSelectedIDsInGridView(this.gvPurchaseOrderDetail, "Status");
                if ((listStatus != null) && (listStatus.Count > 0))
                {
                    for (int i = 0; i < listStatus.Count; i++)
                    {
                        if (listStatus[i].ToUpper() != "NEW")
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F3100_009");
                            return;
                        }
                    }
                }
                try
                {
                    if ((poIDS.Count > 0) && (lineID.Count > 0))
                    {
                        this.lblMsg.Text = OrderDetailMgtServiceClientProxy.GetInstance().DeletePurchaseOrderDetailInfo(poIDS, lineID) + base.GetGlobalMsgResource("C006");
                        this.SetPurchaseOrderInfo2Form();
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F3100_010");
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F3100_011") + ex.Message;
                }
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_012");
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("PurchaseOrderQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("PurchaseOrderList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnImportData_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                {
                    if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4100_002");
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(this.hdnLineID.Value))
                        {
                            this.InsertPurchaseOrderInfo();
                            this.hdnLineID.Value = "10";
                        }
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);DataImport();</script>", false);
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_002");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,6);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtPoDate.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_003");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,6);</script>", false);
            }
            else
            {
                if (this.hdnFlag.Value == "1")
                {
                    this.UpdatePurchaseOrderInfo();
                }
                else
                {
                    this.InsertPurchaseOrderInfo();
                    this.btnAddDetail.Visible = true;
                    this.btnDeleteDetail.Visible = true;
                }
                this.CountrolsClick();
                this.hdnPageQty.Value = "0";
            }
        }

        private void CountrolsClick()
        {
            this.txtPoID.Attributes.Add("RecordValue", "0");
            this.txtPoID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPoID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtExternalPoID.Attributes.Add("RecordValue", "0");
            this.txtExternalPoID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtExternalPoID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPoDate.Attributes.Add("RecordValue", "0");
            this.txtPoDate.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPoDate.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwnerID.Attributes.Add("RecordValue", "0");
            this.txtOwnerID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwnerID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPoGroup.Attributes.Add("RecordValue", "0");
            this.txtPoGroup.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPoGroup.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtExternalPoID2.Attributes.Add("RecordValue", "0");
            this.txtExternalPoID2.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtExternalPoID2.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtClosedDate.Attributes.Add("RecordValue", "0");
            this.txtClosedDate.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtClosedDate.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOtherRef.Attributes.Add("RecordValue", "0");
            this.txtOtherRef.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOtherRef.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlStatus.Attributes.Add("RecordValue", "0");
            this.ddlStatus.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlStatus.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwnerName.Attributes.Add("RecordValue", "0");
            this.txtOwnerName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwnerName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_City.Attributes.Add("RecordValue", "0");
            this.txtOwner_City.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_City.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Contact.Attributes.Add("RecordValue", "0");
            this.txtOwner_Contact.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Contact.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Ref.Attributes.Add("RecordValue", "0");
            this.txtOwner_Ref.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Ref.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Vat.Attributes.Add("RecordValue", "0");
            this.txtOwner_Vat.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Vat.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Porv.Attributes.Add("RecordValue", "0");
            this.txtOwner_Porv.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Porv.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Fax.Attributes.Add("RecordValue", "0");
            this.txtOwner_Fax.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Fax.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Address.Attributes.Add("RecordValue", "0");
            this.txtOwner_Address.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Address.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Zip.Attributes.Add("RecordValue", "0");
            this.txtOwner_Zip.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Zip.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Phone.Attributes.Add("RecordValue", "0");
            this.txtOwner_Phone.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Phone.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Country.Attributes.Add("RecordValue", "0");
            this.txtOwner_Country.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Country.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwner_Email.Attributes.Add("RecordValue", "0");
            this.txtOwner_Email.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwner_Email.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendorName.Attributes.Add("RecordValue", "0");
            this.txtVendorName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_City.Attributes.Add("RecordValue", "0");
            this.txtVendor_City.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_City.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Contact.Attributes.Add("RecordValue", "0");
            this.txtVendor_Contact.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Contact.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Ref.Attributes.Add("RecordValue", "0");
            this.txtVendor_Ref.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Ref.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Vat.Attributes.Add("RecordValue", "0");
            this.txtVendor_Vat.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Vat.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Porv.Attributes.Add("RecordValue", "0");
            this.txtVendor_Porv.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Porv.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Fax.Attributes.Add("RecordValue", "0");
            this.txtVendor_Fax.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Fax.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Address.Attributes.Add("RecordValue", "0");
            this.txtVendor_Address.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Address.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Zip.Attributes.Add("RecordValue", "0");
            this.txtVendor_Zip.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Zip.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Phone.Attributes.Add("RecordValue", "0");
            this.txtVendor_Phone.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Phone.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Country.Attributes.Add("RecordValue", "0");
            this.txtVendor_Country.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Country.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendor_Email.Attributes.Add("RecordValue", "0");
            this.txtVendor_Email.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendor_Email.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtCarrier.Attributes.Add("RecordValue", "0");
            this.txtCarrier.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtCarrier.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtSrcCountry.Attributes.Add("RecordValue", "0");
            this.txtSrcCountry.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtSrcCountry.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlApportionRule.Attributes.Add("RecordValue", "0");
            this.ddlApportionRule.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlApportionRule.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVessel.Attributes.Add("RecordValue", "0");
            this.txtVessel.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVessel.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlIncoTerms.Attributes.Add("RecordValue", "0");
            this.ddlIncoTerms.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlIncoTerms.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtDesCountry.Attributes.Add("RecordValue", "0");
            this.txtDesCountry.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtDesCountry.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVoyge.Attributes.Add("RecordValue", "0");
            this.txtVoyge.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVoyge.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlTransMode.Attributes.Add("RecordValue", "0");
            this.ddlTransMode.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlTransMode.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPlaceOfLoading.Attributes.Add("RecordValue", "0");
            this.txtPlaceOfLoading.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPlaceOfLoading.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtSealNo.Attributes.Add("RecordValue", "0");
            this.txtSealNo.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtSealNo.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlPaymentTerm.Attributes.Add("RecordValue", "0");
            this.ddlPaymentTerm.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlPaymentTerm.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVesselDate.Attributes.Add("RecordValue", "0");
            this.txtVesselDate.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVesselDate.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPlaceOfDelivery.Attributes.Add("RecordValue", "0");
            this.txtPlaceOfDelivery.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPlaceOfDelivery.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf1.Attributes.Add("RecordValue", "0");
            this.txtUdf1.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf1.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf2.Attributes.Add("RecordValue", "0");
            this.txtUdf2.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf2.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf3.Attributes.Add("RecordValue", "0");
            this.txtUdf3.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf3.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf4.Attributes.Add("RecordValue", "0");
            this.txtUdf4.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf4.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf5.Attributes.Add("RecordValue", "0");
            this.txtUdf5.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf5.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf6.Attributes.Add("RecordValue", "0");
            this.txtUdf6.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf6.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf7.Attributes.Add("RecordValue", "0");
            this.txtUdf7.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf7.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf8.Attributes.Add("RecordValue", "0");
            this.txtUdf8.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf8.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf9.Attributes.Add("RecordValue", "0");
            this.txtUdf9.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf9.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf10.Attributes.Add("RecordValue", "0");
            this.txtUdf10.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf10.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtRemark.Attributes.Add("RecordValue", "0");
            this.txtRemark.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtRemark.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtCreatedBy.Attributes.Add("RecordValue", "0");
            this.txtCreatedBy.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtCreatedBy.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtCreatedDate.Attributes.Add("RecordValue", "0");
            this.txtCreatedDate.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtCreatedDate.Text + "',this, 'hdnPageQty'); return true; ");
        }

        protected void gvPurchaseOrderDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F3011", this.gvPurchaseOrderDetail);
        }

        protected void gvPurchaseOrderDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as PurchaseOrderInfo).PurchaseOrderDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,6) </script>", false);
        }

        protected void gvPurchaseOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvPurchaseOrderDetail.PageIndex * this.gvPurchaseOrderDetail.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
            }
        }

        protected void gvPurchaseOrderDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                PurchaseOrderInfo purchaseOrderInfo = base.DataEntityViewState as PurchaseOrderInfo;
                DataView dv = CADataConverter.ToDataTable(purchaseOrderInfo.PurchaseOrderDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvPurchaseOrderDetail, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
            }
        }

        protected void hdnServerPoID_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                PurchaseOrderInfo purchaseOrderInfo = base.DataEntityViewState as PurchaseOrderInfo;
                purchaseOrderInfo = this.SetPurchaseOrderInfo(purchaseOrderInfo);
                purchaseOrderInfo.UpdatedBy = base.UserInfo.UserID;
                purchaseOrderInfo.Status = "Close";
                purchaseOrderInfo.ClosedDate = DateTime.Now;
                OrderMgtServiceClientProxy.GetInstance().UpdatePurchaseOrderInfo(purchaseOrderInfo);
                this.lblMsg.Text = this.txtPoID.Text + base.GetGlobalMsgResource("F3100_013");
            }
            catch
            {
                this.lblMsg.Text = this.txtPoID.Text + base.GetGlobalMsgResource("F3100_014");
            }
        }

        private void InsertPurchaseOrderInfo()
        {
            try
            {
                PurchaseOrderInfo purchaseOrderInfo = new PurchaseOrderInfo();
                if (base.DataEntityViewState != null)
                {
                    purchaseOrderInfo = base.DataEntityViewState as PurchaseOrderInfo;
                }
                purchaseOrderInfo = this.SetPurchaseOrderInfo(purchaseOrderInfo);
                purchaseOrderInfo.CreatedBy = base.UserInfo.UserID;
                purchaseOrderInfo.CreatedDate = DateTime.Now;
                string poID = OrderMgtServiceClientProxy.GetInstance().InsertPurchaseOrderInfo(purchaseOrderInfo);
                this.lblMsg.Text = poID + base.GetGlobalMsgResource("C004");
                this.txtPoID.Text = poID;
                this.hdnpoID.Value = poID;
                base.DataEntityViewState = purchaseOrderInfo;
                this.hdnFlag.Value = "1";
                this.txtPoID.Enabled = false;
                if ((purchaseOrderInfo.PurchaseOrderDetailInfos != null) && (purchaseOrderInfo.PurchaseOrderDetailInfos.Count > 0))
                {
                    this.hdnLineID.Value = (purchaseOrderInfo.PurchaseOrderDetailInfos[purchaseOrderInfo.PurchaseOrderDetailInfos.Count - 1].LineID + 10).ToString();
                }
                else
                {
                    this.hdnLineID.Value = "10";
                }
                if (this.hdnCopy.Value == "1")
                {
                    this.SetPurchaseOrderInfo2Form();
                    this.btnAddDetail.Visible = true;
                    this.btnDeleteDetail.Visible = true;
                    this.btnImportData.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        protected void lnkbtnClose_Click(object sender, EventArgs e)
        {
            string status = this.ddlStatus.SelectedValue.ToUpper();
            if (!(string.IsNullOrEmpty(this.txtPoID.Text.Trim()) || ((status != "NEW") && !(status == "INRECEIVING"))))
            {
                try
                {
                    List<string> initLocal2 = new List<string> {
                        this.txtPoID.Text.Trim()
                    };
                    this.lblMsg.Text = OrderMgtServiceClientProxy.GetInstance().ClosePurchaseOrderInfo(initLocal2) + base.GetGlobalMsgResource("F3100_021");
                    this.SetPurchaseOrderInfo2Form();
                }
                catch (Exception ex)
                {
                    SysLog.GetInstance().LogError(ex);
                    this.lblMsg.Text = ex.Message;
                    this.lblMsg.Visible = true;
                }
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlPoType, "POType");
            base.BindData2DDLBySysCode(this.ddlStatus, "POStatus");
            base.BindData2DDLBySysCode(this.ddlIncoTerms, "IncoTerms");
            base.BindData2DDLBySysCode(this.ddlTransMode, "TransportMode");
            base.BindData2DDLBySysCode(this.ddlPaymentTerm, "PaymentTerms");
            base.BindData2DDLBySysCode(this.ddlApportionRule, "ApportionRule");
            this.ddlStatus.SelectedValue = "New";
            this.txtPoDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            if (string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                base.SetDefaultOwner(this.txtOwnerID);
                this.txtOwnerID_TextChanged(null, null);
            }
            else
            {
                this.hdnpoID.Value = base.Request.QueryString["ID"].ToString();
                this.SetPurchaseOrderInfo2Form();
                this.hdnFlag.Value = "1";
                bool isPSupervisor = false;
                if ((base.UserInfo.UserRoleInfos != null) && (base.UserInfo.UserRoleInfos.Count > 0))
                {
                    for (int n = 0; base.UserInfo.UserRoleInfos.Count > n; n++)
                    {
                        if (base.UserInfo.UserRoleInfos[n].RoleID.ToUpper() == base.GetValueFromAppSettings("PSupervisorRoleID").ToUpper())
                        {
                            isPSupervisor = true;
                            break;
                        }
                    }
                }
                if (!isPSupervisor && (base.UserInfo.UserID != this.txtCreatedBy.Text))
                {
                    this.btnDelete.Enabled = false;
                    this.btnSave.Enabled = false;
                    this.btnAddDetail.Enabled = false;
                    this.btnDeleteDetail.Enabled = false;
                    this.btnImportData.Enabled = false;
                    this.lnkbtnClose.Enabled = false;
                }
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["detail"]))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
                this.CountrolsClick();
            }
        }

        private PurchaseOrderInfo SetPurchaseOrderInfo(PurchaseOrderInfo purchaseOrderInfo)
        {
            DateTime dt = DateTime.Now;
            purchaseOrderInfo.PoID = this.txtPoID.Text.Trim();
            purchaseOrderInfo.ExternalPoID = this.txtExternalPoID.Text.Trim();
            purchaseOrderInfo.Status = this.ddlStatus.SelectedValue;
            if (DateTime.TryParse(this.txtPoDate.Text.Trim(), out dt))
            {
                purchaseOrderInfo.PoDate = DateTime.Parse(this.txtPoDate.Text.Trim());
            }
            else
            {
                purchaseOrderInfo.PoDate = dt;
            }
            purchaseOrderInfo.OwnerID = this.txtOwnerID.Text.Trim();
            purchaseOrderInfo.PoGroup = this.txtPoGroup.Text.Trim();
            purchaseOrderInfo.ExternalPoId2 = this.txtExternalPoID2.Text.Trim();
            if (!string.IsNullOrEmpty(this.txtClosedDate.Text.Trim()))
            {
                purchaseOrderInfo.ClosedDate = DateTime.Parse(this.txtClosedDate.Text.Trim());
            }
            if (!string.IsNullOrEmpty(this.txtRequestDeliveryDate.Text.Trim()))
            {
                purchaseOrderInfo.RequestDeliveryDate = DateTime.Parse(this.txtRequestDeliveryDate.Text.Trim());
            }
            purchaseOrderInfo.VendorID = this.txtVendorID.Text.Trim();
            purchaseOrderInfo.PoType = this.ddlPoType.SelectedValue;
            purchaseOrderInfo.OtherRef = this.txtOtherRef.Text.Trim();
            purchaseOrderInfo.OwnerName = this.txtOwnerName.Text.Trim();
            purchaseOrderInfo.OwnerCity = this.txtOwner_City.Text.Trim();
            purchaseOrderInfo.OwnerContact = this.txtOwner_Contact.Text.Trim();
            purchaseOrderInfo.OwnerRef = this.txtOwner_Ref.Text.Trim();
            purchaseOrderInfo.OwnerVat = this.txtOwner_Vat.Text.Trim();
            purchaseOrderInfo.OwnerProv = this.txtOwner_Porv.Text.Trim();
            purchaseOrderInfo.OwnerFax = this.txtOwner_Fax.Text.Trim();
            purchaseOrderInfo.OwnerAddress = this.txtOwner_Address.Text.Trim();
            purchaseOrderInfo.OwnerZip = this.txtOwner_Zip.Text.Trim();
            purchaseOrderInfo.OwnerPhone = this.txtOwner_Phone.Text.Trim();
            purchaseOrderInfo.OwnerCountry = this.txtOwner_Country.Text.Trim();
            purchaseOrderInfo.OwnerEmail = this.txtOwner_Email.Text.Trim();
            purchaseOrderInfo.VendorName = this.txtVendorName.Text.Trim();
            purchaseOrderInfo.VendorCity = this.txtVendor_City.Text.Trim();
            purchaseOrderInfo.VendorContact = this.txtVendor_Contact.Text.Trim();
            purchaseOrderInfo.VendorRef = this.txtVendor_Ref.Text.Trim();
            purchaseOrderInfo.VendorVat = this.txtVendor_Vat.Text.Trim();
            purchaseOrderInfo.VendorProv = this.txtVendor_Porv.Text.Trim();
            purchaseOrderInfo.VendorFax = this.txtVendor_Fax.Text.Trim();
            purchaseOrderInfo.VendorAddress = this.txtVendor_Address.Text.Trim();
            purchaseOrderInfo.VendorZip = this.txtVendor_Zip.Text.Trim();
            purchaseOrderInfo.VendorPhone = this.txtVendor_Phone.Text.Trim();
            purchaseOrderInfo.VendorCountry = this.txtVendor_Country.Text.Trim();
            purchaseOrderInfo.VendorEmail = this.txtVendor_Email.Text.Trim();
            purchaseOrderInfo.Carrier = this.txtCarrier.Text.Trim();
            purchaseOrderInfo.SrcCountry = this.txtSrcCountry.Text.Trim();
            purchaseOrderInfo.ApportionRule = this.ddlApportionRule.SelectedValue;
            purchaseOrderInfo.Vessel = this.txtVessel.Text.Trim();
            purchaseOrderInfo.IncoTerms = this.ddlIncoTerms.SelectedValue;
            purchaseOrderInfo.DestCountry = this.txtDesCountry.Text.Trim();
            purchaseOrderInfo.Voyage = this.txtVoyge.Text.Trim();
            purchaseOrderInfo.TransMode = this.ddlTransMode.SelectedValue;
            purchaseOrderInfo.PlaceOfLoading = this.txtPlaceOfLoading.Text.Trim();
            purchaseOrderInfo.SealNo = this.txtSealNo.Text.Trim();
            purchaseOrderInfo.PaymentTerm = this.ddlPaymentTerm.SelectedValue;
            purchaseOrderInfo.PlaceOfDischarge = this.txtPlaceOfDischarge.Text.Trim();
            if (DateTime.TryParse(this.txtVesselDate.Text.Trim(), out dt))
            {
                purchaseOrderInfo.VesselDate = DateTime.Parse(this.txtVesselDate.Text.Trim());
            }
            else
            {
                purchaseOrderInfo.VesselDate = dt;
            }
            purchaseOrderInfo.PlaceOfDelivery = this.txtPlaceOfDelivery.Text.Trim();
            purchaseOrderInfo.Udf1 = this.txtUdf1.Text.Trim();
            purchaseOrderInfo.Udf2 = this.txtUdf2.Text.Trim();
            purchaseOrderInfo.Udf3 = this.txtUdf3.Text.Trim();
            purchaseOrderInfo.Udf4 = this.txtUdf4.Text.Trim();
            purchaseOrderInfo.Udf5 = this.txtUdf5.Text.Trim();
            purchaseOrderInfo.Udf6 = this.txtUdf6.Text.Trim();
            purchaseOrderInfo.Udf7 = this.txtUdf7.Text.Trim();
            purchaseOrderInfo.Udf8 = this.txtUdf8.Text.Trim();
            purchaseOrderInfo.Udf9 = this.txtUdf9.Text.Trim();
            purchaseOrderInfo.Udf10 = this.txtUdf10.Text.Trim();
            purchaseOrderInfo.Remark = this.txtRemark.Text.Trim();
            purchaseOrderInfo.IsActive = "Y";
            return purchaseOrderInfo;
        }

        private void SetPurchaseOrderInfo2Form()
        {
            try
            {
                string poID = this.hdnpoID.Value.ToString();
                PurchaseOrderInfo purchaseOrderInfo = OrderMgtServiceClientProxy.GetInstance().GetPurchaseOrderInfoByPoID(poID);
                base.DataEntityViewState = purchaseOrderInfo;
                if (purchaseOrderInfo != null)
                {
                    this.SetPurchaseOrderInfo2Form(purchaseOrderInfo);
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void SetPurchaseOrderInfo2Form(PurchaseOrderInfo purchaseOrderInfo)
        {
            this.txtPoID.Text = purchaseOrderInfo.PoID;
            this.txtExternalPoID.Text = purchaseOrderInfo.ExternalPoID;
            this.txtPoDate.Text = base.GetPreferenceShortDate(purchaseOrderInfo.PoDate);
            this.txtOwnerID.Text = purchaseOrderInfo.OwnerID;
            this.txtOwnerID.Enabled = false;
            this.imgOwnerID.Visible = false;
            this.txtPoGroup.Text = purchaseOrderInfo.PoGroup;
            this.txtExternalPoID2.Text = purchaseOrderInfo.ExternalPoId2;
            if (!string.IsNullOrEmpty(purchaseOrderInfo.ClosedDate.ToShortDateString()))
            {
                this.txtClosedDate.Text = base.GetPreferenceShortDate(purchaseOrderInfo.ClosedDate);
            }
            if (!string.IsNullOrEmpty(purchaseOrderInfo.RequestDeliveryDate.ToShortDateString()))
            {
                this.txtRequestDeliveryDate.Text = base.GetPreferenceShortDate(purchaseOrderInfo.RequestDeliveryDate);
            }
            this.txtVendorID.Text = purchaseOrderInfo.VendorID;
            this.ddlPoType.SelectedValue = purchaseOrderInfo.PoType;
            this.txtOtherRef.Text = purchaseOrderInfo.OtherRef;
            this.ddlStatus.SelectedValue = purchaseOrderInfo.Status;
            this.txtOwnerName.Text = purchaseOrderInfo.OwnerName;
            this.txtOwner_City.Text = purchaseOrderInfo.OwnerCity;
            this.txtOwner_Contact.Text = purchaseOrderInfo.OwnerContact;
            this.txtOwner_Ref.Text = purchaseOrderInfo.OwnerRef;
            this.txtOwner_Vat.Text = purchaseOrderInfo.OwnerVat;
            this.txtOwner_Porv.Text = purchaseOrderInfo.OwnerProv;
            this.txtOwner_Fax.Text = purchaseOrderInfo.OwnerFax;
            this.txtOwner_Address.Text = purchaseOrderInfo.OwnerAddress;
            this.txtOwner_Zip.Text = purchaseOrderInfo.OwnerZip;
            this.txtOwner_Phone.Text = purchaseOrderInfo.OwnerPhone;
            this.txtOwner_Country.Text = purchaseOrderInfo.OwnerCountry;
            this.txtOwner_Email.Text = purchaseOrderInfo.OwnerEmail;
            this.txtVendorName.Text = purchaseOrderInfo.VendorName;
            this.txtVendor_City.Text = purchaseOrderInfo.VendorCity;
            this.txtVendor_Contact.Text = purchaseOrderInfo.VendorContact;
            this.txtVendor_Ref.Text = purchaseOrderInfo.VendorRef;
            this.txtVendor_Vat.Text = purchaseOrderInfo.VendorVat;
            this.txtVendor_Porv.Text = purchaseOrderInfo.VendorProv;
            this.txtVendor_Fax.Text = purchaseOrderInfo.VendorFax;
            this.txtVendor_Address.Text = purchaseOrderInfo.VendorAddress;
            this.txtVendor_Zip.Text = purchaseOrderInfo.VendorZip;
            this.txtVendor_Phone.Text = purchaseOrderInfo.VendorPhone;
            this.txtVendor_Country.Text = purchaseOrderInfo.VendorCountry;
            this.txtVendor_Email.Text = purchaseOrderInfo.VendorEmail;
            this.txtCarrier.Text = purchaseOrderInfo.Carrier;
            this.txtSrcCountry.Text = purchaseOrderInfo.SrcCountry;
            this.ddlApportionRule.SelectedValue = purchaseOrderInfo.ApportionRule;
            this.txtVessel.Text = purchaseOrderInfo.Vessel;
            this.ddlIncoTerms.SelectedValue = purchaseOrderInfo.IncoTerms;
            this.txtDesCountry.Text = purchaseOrderInfo.DestCountry;
            this.txtVoyge.Text = purchaseOrderInfo.Voyage;
            this.ddlTransMode.SelectedValue = purchaseOrderInfo.TransMode;
            this.txtPlaceOfLoading.Text = purchaseOrderInfo.PlaceOfLoading;
            this.txtSealNo.Text = purchaseOrderInfo.SealNo;
            this.ddlPaymentTerm.SelectedValue = purchaseOrderInfo.PaymentTerm;
            this.txtPlaceOfDischarge.Text = purchaseOrderInfo.PlaceOfDischarge;
            this.txtVesselDate.Text = base.GetPreferenceShortDate(purchaseOrderInfo.VesselDate);
            this.txtPlaceOfDelivery.Text = purchaseOrderInfo.PlaceOfDelivery;
            this.txtUdf1.Text = purchaseOrderInfo.Udf1;
            this.txtUdf2.Text = purchaseOrderInfo.Udf2;
            this.txtUdf3.Text = purchaseOrderInfo.Udf3;
            this.txtUdf4.Text = purchaseOrderInfo.Udf4;
            this.txtUdf5.Text = purchaseOrderInfo.Udf5;
            this.txtUdf6.Text = purchaseOrderInfo.Udf6;
            this.txtUdf7.Text = purchaseOrderInfo.Udf7;
            this.txtUdf8.Text = purchaseOrderInfo.Udf8;
            this.txtUdf9.Text = purchaseOrderInfo.Udf9;
            this.txtUdf10.Text = purchaseOrderInfo.Udf10;
            this.txtRemark.Text = purchaseOrderInfo.Remark;
            this.txtCreatedBy.Text = purchaseOrderInfo.CreatedBy;
            this.txtCreatedDate.Text = base.GetPreferenceShortDate(purchaseOrderInfo.CreatedDate);
            if ((purchaseOrderInfo.PurchaseOrderDetailInfos != null) && (purchaseOrderInfo.PurchaseOrderDetailInfos.Count > 0))
            {
                purchaseOrderInfo.PurchaseOrderDetailInfos.Sort((Comparison<PurchaseOrderDetailInfo>) ((p1, p2) => Comparer<int>.Default.Compare(p1.LineID, p2.LineID)));
                this.hdnLineID.Value = (purchaseOrderInfo.PurchaseOrderDetailInfos[purchaseOrderInfo.PurchaseOrderDetailInfos.Count - 1].LineID + 10).ToString();
            }
            else
            {
                this.hdnLineID.Value = "10";
            }
            base.BindData2GridView(this.gvPurchaseOrderDetail, purchaseOrderInfo.PurchaseOrderDetailInfos);
            this.txtPoID.Enabled = false;
            this.txtOwnerID.Enabled = false;
        }

        protected void txtOwnerID_TextChanged(object sender, EventArgs e)
        {
            TradePartnerInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtOwnerID.Text.Trim(), "TRADE_PARTNER") as TradePartnerInfo;
            if (tradePartnerInfo != null)
            {
                this.txtOwnerName.Text = tradePartnerInfo.Company;
                this.txtOwner_City.Text = tradePartnerInfo.City;
                this.txtOwner_Address.Text = tradePartnerInfo.Address;
                this.txtOwner_Contact.Text = tradePartnerInfo.Contact1;
                this.txtOwner_Country.Text = tradePartnerInfo.Country;
                this.txtOwner_Email.Text = tradePartnerInfo.Email1;
                this.txtOwner_Fax.Text = tradePartnerInfo.Fax1;
                this.txtOwner_Phone.Text = tradePartnerInfo.Phone1;
                this.txtOwner_Porv.Text = tradePartnerInfo.State;
                this.txtOwner_Vat.Text = tradePartnerInfo.Vat;
                this.txtOwner_Zip.Text = tradePartnerInfo.Zip;
            }
            this.hdnPageType.Value = "0";
            this.txtOwnerID.Focus();
        }

        protected void txtPoID_TextChanged(object sender, EventArgs e)
        {
            if (this.hdnCopy.Value != "1")
            {
                this.hdnpoID.Value = this.txtPoID.Text.Trim();
                this.SetPurchaseOrderInfo2Form();
            }
        }

        protected void txtVendorID_TextChanged(object sender, EventArgs e)
        {
            VendorInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtVendorID.Text.Trim(), "VENDOR") as VendorInfo;
            if (tradePartnerInfo != null)
            {
                this.txtVendorName.Text = tradePartnerInfo.Company;
                this.txtVendor_Address.Text = tradePartnerInfo.Address;
                this.txtVendor_City.Text = tradePartnerInfo.City;
                this.txtVendor_Contact.Text = tradePartnerInfo.Contact1;
                this.txtVendor_Country.Text = tradePartnerInfo.Country;
                this.txtVendor_Email.Text = tradePartnerInfo.Email1;
                this.txtVendor_Fax.Text = tradePartnerInfo.Fax1;
                this.txtVendor_Phone.Text = tradePartnerInfo.Phone1;
                this.txtVendor_Porv.Text = tradePartnerInfo.State;
                this.txtVendor_Vat.Text = tradePartnerInfo.Vat;
                this.txtVendor_Zip.Text = tradePartnerInfo.Zip;
            }
            this.hdnPageType.Value = "0";
            this.txtVendorID.Focus();
        }

        private void UpdatePurchaseOrderInfo()
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F3100_004");
                }
                else
                {
                    PurchaseOrderInfo purchaseOrderInfo = base.DataEntityViewState as PurchaseOrderInfo;
                    purchaseOrderInfo = this.SetPurchaseOrderInfo(purchaseOrderInfo);
                    purchaseOrderInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = OrderMgtServiceClientProxy.GetInstance().UpdatePurchaseOrderInfo(purchaseOrderInfo) + base.GetGlobalMsgResource("F3100_005");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

